package com.lagou.dao.impl;

import com.lagou.dao.UserService;
import com.lagou.utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ScalarHandler;

import java.sql.SQLException;

public class UserServiceImpl implements UserService {


    @Override
    public boolean isUserExists(String username, String password) {

        String sql = "select count(*) from user where username= ? and password = ?";

        try {

            QueryRunner qr = new QueryRunner(DruidUtils.getDataSource());
            Object[] params = {username,password};

            Long count = qr.query(sql,new ScalarHandler<Long>(),params);

            if (count >0 ) {
                return true;
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }

        return false;
    }
}
